package wechat.base.snd;

import java.util.Collection;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Pure;
import org.json.JSONArray;
import org.json.JSONObject;
import wechat.base.snd.WCSubButton;
import wechat.base.snd.encoding.JsonPut;

@SuppressWarnings("all")
public class WCButton {
  @Accessors
  private String type;
  
  @Accessors
  private String name;
  
  @Accessors
  private String key;
  
  private JsonPut allbtn = new JsonPut();
  
  private Collection<WCSubButton> subbuttons = CollectionLiterals.<WCSubButton>newArrayList();
  
  public void withSubButton(final WCSubButton b) {
    this.subbuttons.add(b);
  }
  
  public JSONObject toJson() {
    try {
      JSONObject _xblockexpression = null;
      {
        this.allbtn.put("name", this.name);
        JSONArray _jSONArray = new JSONArray();
        final Procedure1<JSONArray> _function = new Procedure1<JSONArray>() {
          public void apply(final JSONArray it) {
            for (final WCSubButton b : WCButton.this.subbuttons) {
              JSONObject _json = b.toJson();
              it.put(_json);
            }
          }
        };
        JSONArray _doubleArrow = ObjectExtensions.<JSONArray>operator_doubleArrow(_jSONArray, _function);
        _xblockexpression = this.allbtn.put("sub_button", _doubleArrow);
      }
      return _xblockexpression;
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  @Pure
  public String getType() {
    return this.type;
  }
  
  public void setType(final String type) {
    this.type = type;
  }
  
  @Pure
  public String getName() {
    return this.name;
  }
  
  public void setName(final String name) {
    this.name = name;
  }
  
  @Pure
  public String getKey() {
    return this.key;
  }
  
  public void setKey(final String key) {
    this.key = key;
  }
}
